﻿<!DOCTYPE HTML>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<!-- 插入公共模板 _meta -->
<head th:insert="../templates/admin/common/_meta :: common_meta"></head>
<body>

<!-- 插入公共模板 _header -->
<div th:replace="../templates/admin/common/_header :: common_header"></div>

<!-- 插入公共模板 _menu -->
<div th:replace="../templates/admin/common/_menu :: common_menu"></div>

<section class="Hui-article-box">
	<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 用户管理 <span class="c-gray en">&gt;</span> 用户列表<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
	<div class="Hui-article">
		<article class="cl pd-20">
			<div class="cl pd-5 bg-1 bk-gray mt-20">
				<span class="l">
					<a href="javascript:;" onclick="user_stopBatch()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量停用</a>
					<a href="javascript:;" onclick="user_add('添加用户','goUserAdd','','510')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加用户</a>
				</span>
				<span class="r">共有数据：<strong th:text="${users.size()}"></strong> 条</span>
			</div>
			<div class="mt-20">
				<table class="table table-border table-bordered table-hover table-bg table-sort">
					<thead>
						<tr class="text-c">
							<th width="25"><input type="checkbox" ></th>
							<th width="40">序号</th>
							<th width="80">用户名</th>
							<th width="100">账户余额</th>
							<th width="40">性别</th>
							<th width="90">手机</th>
							<th width="180">注册地址</th>
							<th width="130">入录时间</th>
							<th width="130">修改时间</th>
							<th width="70">状态</th>
							<th width="100">操作</th>
						</tr>
					</thead>
					<tbody>
						<tr class="text-c" th:each="user,var : ${users}">
							<td><input type="checkbox" th:value="${user.userId}" name="userId"></td>
							<td th:text="${var.count}"></td>
							<td th:text="${user.userName}"></td>
							<td th:text="|${#numbers.formatDecimal(user.userAmount/100.0,1,2)}元|"></td>
							<td th:text="${user.sex}"></td>
							<td th:text="${user.phone}"></td>
							<td th:text="|${user.province} - ${user.city} - ${user.country}|"></td>
							<td th:with="createTime=${user.createTime}" th:text="${#dates.format(createTime, 'yyyy-MM-dd HH:mm:ss')}"></td>
							<td th:with="updateTime=${user.updateTime}" th:text="${#dates.format(updateTime, 'yyyy-MM-dd HH:mm:ss')}"></td>
							<td class="td-status">
								<span class="label label-success radius" th:if="${user.state == 1}">已启用</span>
								<span class="label label-defaunt radius" th:if="${user.state == 0}">已停用</span>
							</td>
							<td class="td-manage">
								<a th:if="${user.state == 1}" style="text-decoration:none" th:onClick="|user_stop(this,${user.userId},'stop')|" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>
								<a th:if="${user.state == 0}" style="text-decoration:none" th:onClick="|user_start(this,${user.userId},'start')|" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe6e1;</i></a>
								<a style="text-decoration:none" class="ml-5" th:onclick="|user_edit('编辑','goUserEdit',${user.userId},'','510')|" title="编辑" href="javascript:;" ><i class="Hui-iconfont">&#xe6df;</i></a>
								<a style="text-decoration:none" class="ml-5" th:onClick="|change_password('修改密码','goUserChangePassword',${user.userId},'600','270')|" href="javascript:;" title="修改密码"><i class="Hui-iconfont">&#xe63f;</i></a>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</article>
	</div>
</section>

<!-- 插入公共模版 _footer -->
<div th:replace="../templates/admin/common/_footer :: common_footer"></div>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../../lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="../../lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" th:inline="none">

	/*用户-添加*/
	function user_add(title,url,w,h){
		layer_show(title,url,w,h);
	}

	/*用户-批量停用*/
	function user_stopBatch() {
		var obj = document.getElementsByName("userId");
		var userIds = [];
		for(i in obj) {
			if(obj[i].checked){
				userIds.push(obj[i].value);
			}
		}
		layer.confirm('确认要停用吗？',function(index){
			$.ajax({
				type: "GET",
				dateType: "json",
				url: "stopBatchUser"+"?userIds="+userIds,
				success: function (result) {
					if(result.flag = "true") {
						layer.msg('停用成功,请刷新!',{icon: 6,time:1000});
					} else {
						layer.msg('失败,含有'+result.number+'个停用失败!',{icon: 2,time:1000});
					}
				},
				error: function (err) {
					layer.msg('请求异常!',{icon: 2,time:1000})
				}
			});
		});
	}

	/*用户-停用*/
	function user_stop(obj,userId,state){
		layer.confirm('确认要停用吗？',function(index){
			$.ajax({
				type: "GET",
				dateType: "json",
				url: "doUserState"+"?userId="+userId + "&state=" + state,
				success: function (result) {
					if(result.flag = "true") {
						$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="user_start(this,'+userId+',\'start\')" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe6e1;</i></a>');
						$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已停用</span>');
						$(obj).remove();
						layer.msg('已停用!',{icon: 5,time:1000});
					} else {
						layer.msg('停用失败!',{icon: 2,time:1000});
					}
				},
				error: function (err) {
					layer.msg('请求异常!',{icon: 2,time:1000})
				}
			});
		});
	}

	/*用户-启用*/
	function user_start(obj,userId,state){
		layer.confirm('确认要启用吗？',function(index){
			$.ajax({
				type: "GET",
				dateType: "json",
				url: "doUserState" + "?userId=" + userId + "&state=" + state,
				success: function (result) {
					if(result.flag = "true") {
						$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="user_stop(this,'+userId+',\'stop\')" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>');
						$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
						$(obj).remove();
						layer.msg('已启用!',{icon: 6,time:1000});
					} else {
						layer.msg('启用失败!',{icon: 2,time:1000});
					}
				},
				error: function (err) {
					layer.msg('请求异常!',{icon: 2,time:1000})
				}
			});
		});
	}

	/*用户-编辑*/
	function user_edit(title,url,userId,w,h){
		url = url + "?userId=" + userId;
		layer_show(title,url,w,h);
	}

	/*密码-修改*/
	function change_password(title,url,userId,w,h){
		url = url + "?userId=" + userId;
		layer_show(title,url,w,h);
	}

	/* 表格配置 */
	$(function(){
		$('.table-sort').dataTable({
			"aaSorting": [[ 1, "asc" ]],//默认第几个排序
			"bStateSave": true,//状态保存
			"aoColumnDefs": [
			  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
			  {"orderable":false,"aTargets":[0,9,10]}// 制定列不参与排序
			]
		});


	});

</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>